//
//  PreLoadController_h.m
//  linlee-iotios
//
//  Created by mengze on 2025/5/25.
//

#import <Foundation/Foundation.h>
#import "Masonry.h"
#import "PreLoadMachineController.h"
#import "BlueDeviceListController.h"


@interface PreLoadMachineController()

@property (nonatomic, strong) UITextField *loadCodeField;
@property (nonatomic, strong) UIButton *loadCodeButton;

@property (nonatomic, strong)  UILabel *asteriskLabel;
@property (nonatomic, strong)  UILabel *hintLabel;

@end


@implementation PreLoadMachineController

- ( void ) viewDidLoad {
    [self.view setBackgroundColor:[UIColor whiteColor]];
    [self.navigationItem setTitle:@"预装机部署"];
    
    
    [self initView];
    [self initViewData];
}


- ( void ) initView {
    
    // 创建第一个红色星号Label
    self.asteriskLabel = [[UILabel alloc] init];
    self.asteriskLabel.text = @"*";
    self.asteriskLabel.textColor = [UIColor redColor];
    self.asteriskLabel.font = [UIFont systemFontOfSize:12];
    [self.view addSubview:self.asteriskLabel];

    // 创建第二个灰色提示Label
    UILabel *hintLabel = [[UILabel alloc] init];
    hintLabel.text = @"注意区分大小写";
    hintLabel.textColor = [UIColor colorWithRed:153/255.0 green:153/255.0 blue:153/255.0 alpha:1.0];
    hintLabel.font = [UIFont systemFontOfSize:12];
    [self.view addSubview:hintLabel];
    self.hintLabel= hintLabel;

    
    // 用户名输入框
    self.loadCodeField = [[UITextField alloc] init];
    self.loadCodeField.placeholder = @"请输入设备部署码";
    self.loadCodeField.borderStyle = UITextBorderStyleRoundedRect;
    [self.view addSubview:self.loadCodeField];
    
    
    // 登录按钮
    self.loadCodeButton = [UIButton buttonWithType:UIButtonTypeSystem];
    [self.loadCodeButton setTitle:@"开始部署" forState:UIControlStateNormal];
    self.loadCodeButton.backgroundColor = [UIColor greenColor];
    [self.loadCodeButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    self.loadCodeButton.font = [UIFont systemFontOfSize:18];
    self.loadCodeButton.layer.cornerRadius = 6;
    self.loadCodeButton.layer.masksToBounds = YES;
    [self.loadCodeButton addTarget:self action:@selector(startPreLoadAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.loadCodeButton];
}


- ( void ) initViewData {

    
    // 使用Masonry布局
    [self.loadCodeField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).offset(160);
        make.left.equalTo( self.view ).offset(20);
        make.right.equalTo( self.view ).offset(-20);
        make.height.equalTo( @52 );
    }];
    
    UIView * usernameLeftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 12, 12)];
    self.loadCodeField.leftView= usernameLeftView;
    self.loadCodeField.leftViewMode = UITextFieldViewModeAlways;
    
    
    // 使用Masonry布局
    [self.asteriskLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.loadCodeField);
        make.top.equalTo(self.loadCodeField.mas_bottom).offset(6);
    }];

    [self.hintLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.asteriskLabel.mas_right).offset(5);
        make.centerY.equalTo(self.asteriskLabel);
    }];

    
    [self.loadCodeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.loadCodeField.mas_bottom).offset(60);
        make.width.equalTo(self.loadCodeField);
        make.height.equalTo(self.loadCodeField);
        make.centerX.equalTo(self.loadCodeField );
        make.height.equalTo(@52);
    }];
    
}


- (void)startPreLoadAction:(id) sender {
    BlueDeviceListController * vc = [[BlueDeviceListController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}



@end
